﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class MicroWebsiteOrderLog
    {
        private readonly Chain.IDAL.MicroWebsiteOrderLog dal = new Chain.IDAL.MicroWebsiteOrderLog();

        public int Add(Chain.Model.MicroWebsiteOrderLog model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.MicroWebsiteOrderLog> DataTableToList(DataTable dt)
        {
            List<Chain.Model.MicroWebsiteOrderLog> list = new List<Chain.Model.MicroWebsiteOrderLog>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.MicroWebsiteOrderLog item = new Chain.Model.MicroWebsiteOrderLog();
                    if ((dt.Rows[i]["MicroOrderID"] != null) && (dt.Rows[i]["MicroOrderID"].ToString() != ""))
                    {
                        item.MicroOrderID = int.Parse(dt.Rows[i]["MicroOrderID"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderAccount"] != null) && (dt.Rows[i]["MicroOrderAccount"].ToString() != ""))
                    {
                        item.MicroOrderAccount = dt.Rows[i]["MicroOrderAccount"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderType"] != null) && (dt.Rows[i]["MicroOrderType"].ToString() != ""))
                    {
                        item.MicroOrderType = int.Parse(dt.Rows[i]["MicroOrderType"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderMemID"] != null) && (dt.Rows[i]["MicroOrderMemID"].ToString() != ""))
                    {
                        item.MicroOrderMemID = int.Parse(dt.Rows[i]["MicroOrderMemID"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderTotalMoney"] != null) && (dt.Rows[i]["MicroOrderTotalMoney"].ToString() != ""))
                    {
                        item.MicroOrderTotalMoney = decimal.Parse(dt.Rows[i]["MicroOrderTotalMoney"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderDiscountMoney"] != null) && (dt.Rows[i]["MicroOrderDiscountMoney"].ToString() != ""))
                    {
                        item.MicroOrderDiscountMoney = decimal.Parse(dt.Rows[i]["MicroOrderDiscountMoney"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderIsCard"] != null) && (dt.Rows[i]["MicroOrderIsCard"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["MicroOrderIsCard"].ToString() == "1") || (dt.Rows[i]["MicroOrderIsCard"].ToString().ToLower() == "true"))
                        {
                            item.MicroOrderIsCard = true;
                        }
                        else
                        {
                            item.MicroOrderIsCard = false;
                        }
                    }
                    if ((dt.Rows[i]["MicroOrderPayCard"] != null) && (dt.Rows[i]["MicroOrderPayCard"].ToString() != ""))
                    {
                        item.MicroOrderPayCard = decimal.Parse(dt.Rows[i]["MicroOrderPayCard"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderIsCash"] != null) && (dt.Rows[i]["MicroOrderIsCash"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["MicroOrderIsCash"].ToString() == "1") || (dt.Rows[i]["MicroOrderIsCash"].ToString().ToLower() == "true"))
                        {
                            item.MicroOrderIsCash = true;
                        }
                        else
                        {
                            item.MicroOrderIsCash = false;
                        }
                    }
                    if ((dt.Rows[i]["MicroOrderPayCash"] != null) && (dt.Rows[i]["MicroOrderPayCash"].ToString() != ""))
                    {
                        item.MicroOrderPayCash = decimal.Parse(dt.Rows[i]["MicroOrderPayCash"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderIsBink"] != null) && (dt.Rows[i]["MicroOrderIsBink"].ToString() != ""))
                    {
                        if ((dt.Rows[i]["MicroOrderIsBink"].ToString() == "1") || (dt.Rows[i]["MicroOrderIsBink"].ToString().ToLower() == "true"))
                        {
                            item.MicroOrderIsBink = true;
                        }
                        else
                        {
                            item.MicroOrderIsBink = false;
                        }
                    }
                    if ((dt.Rows[i]["MicroOrderPayBink"] != null) && (dt.Rows[i]["MicroOrderPayBink"].ToString() != ""))
                    {
                        item.MicroOrderPayBink = decimal.Parse(dt.Rows[i]["MicroOrderPayBink"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderPayCoupon"] != null) && (dt.Rows[i]["MicroOrderPayCoupon"].ToString() != ""))
                    {
                        item.MicroOrderPayCoupon = decimal.Parse(dt.Rows[i]["MicroOrderPayCoupon"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderPoint"] != null) && (dt.Rows[i]["MicroOrderPoint"].ToString() != ""))
                    {
                        item.MicroOrderPoint = int.Parse(dt.Rows[i]["MicroOrderPoint"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderRemark"] != null) && (dt.Rows[i]["MicroOrderRemark"].ToString() != ""))
                    {
                        item.MicroOrderRemark = dt.Rows[i]["MicroOrderRemark"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderShopID"] != null) && (dt.Rows[i]["MicroOrderShopID"].ToString() != ""))
                    {
                        item.MicroOrderShopID = int.Parse(dt.Rows[i]["MicroOrderShopID"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderUserID"] != null) && (dt.Rows[i]["MicroOrderUserID"].ToString() != ""))
                    {
                        item.MicroOrderUserID = int.Parse(dt.Rows[i]["MicroOrderUserID"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderCreateTime"] != null) && (dt.Rows[i]["MicroOrderCreateTime"].ToString() != ""))
                    {
                        item.MicroOrderCreateTime = DateTime.Parse(dt.Rows[i]["MicroOrderCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOldAccount"] != null) && (dt.Rows[i]["MicroOldAccount"].ToString() != ""))
                    {
                        item.MicroOldAccount = dt.Rows[i]["MicroOldAccount"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderCardBalance"] != null) && (dt.Rows[i]["MicroOrderCardBalance"].ToString() != ""))
                    {
                        item.MicroOrderCardBalance = decimal.Parse(dt.Rows[i]["MicroOrderCardBalance"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderCardPoint"] != null) && (dt.Rows[i]["MicroOrderCardPoint"].ToString() != ""))
                    {
                        item.MicroOrderCardPoint = int.Parse(dt.Rows[i]["MicroOrderCardPoint"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderName"] != null) && (dt.Rows[i]["MicroOrderName"].ToString() != ""))
                    {
                        item.MicroOrderName = dt.Rows[i]["MicroOrderName"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderMobile"] != null) && (dt.Rows[i]["MicroOrderMobile"].ToString() != ""))
                    {
                        item.MicroOrderMobile = dt.Rows[i]["MicroOrderMobile"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderAdress"] != null) && (dt.Rows[i]["MicroOrderAdress"].ToString() != ""))
                    {
                        item.MicroOrderAdress = dt.Rows[i]["MicroOrderAdress"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderStatus"] != null) && (dt.Rows[i]["MicroOrderStatus"].ToString() != ""))
                    {
                        item.MicroOrderStatus = int.Parse(dt.Rows[i]["MicroOrderStatus"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderPassCreateTime"] != null) && (dt.Rows[i]["MicroOrderPassCreateTime"].ToString() != ""))
                    {
                        item.MicroOrderPassCreateTime = DateTime.Parse(dt.Rows[i]["MicroOrderPassCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["MicroOrderMark"] != null) && (dt.Rows[i]["MicroOrderMark"].ToString() != ""))
                    {
                        item.MicroOrderMark = dt.Rows[i]["MicroOrderMark"].ToString();
                    }
                    if ((dt.Rows[i]["MicroOrderPayCreateTime"] != null) && (dt.Rows[i]["MicroOrderPayCreateTime"].ToString() != ""))
                    {
                        item.MicroOrderPayCreateTime = DateTime.Parse(dt.Rows[i]["MicroOrderPayCreateTime"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int MicroOrderID)
        {
            return this.dal.Delete(MicroOrderID);
        }

        public bool DeleteList(string MicroOrderIDlist)
        {
            return this.dal.DeleteList(MicroOrderIDlist);
        }

        public bool Exists(int MicroOrderID)
        {
            return this.dal.Exists(MicroOrderID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetListSP1(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP1(PageSize, PageIndex, out resCount, strWhere);
        }

        public Chain.Model.MicroWebsiteOrderLog GetModel(int MicroOrderID)
        {
            return this.dal.GetModel(MicroOrderID);
        }

        public List<Chain.Model.MicroWebsiteOrderLog> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.MicroWebsiteOrderLog model)
        {
            return this.dal.Update(model);
        }
    }
}

